package model;

import java.awt.Dimension;
import java.util.List;

import controller.Controller;

import model.expression.AbstractExpression;
import model.parser.Parser;
import model.parser.ParserException;


import state.TabState;
import state.TurtleState;
import state.WindowState;

public class Model {
	
	private Parser parser;

	public Model(){
		this.parser=new Parser();
	}
	public Model(Parser parser){
		this.parser=parser;
	}
	
	/**
	 * Control class call the updateTabState method, it would pass the user input and 
	 * current tab ID then return the updated tabState
	 * 
	 * @param msg user input
	 * @param tabID the current tab ID 
	 * @return the updated tabState
	 */
	public TabState updateTabState(String msg, int tabID){
		return null;
	}
	
	private TabState evalETree(AbstractExpression tree){
		return null;
	}
	
	/**
	 * 
	 * @param msg the string to parse
	 * @param tabstate needed to know what the current variables
	 * @return returns the integer the expression evaluates to; 
	 * 			in the case of multiple expressions on a single line it
	 * 			evaluates to the last one
	 * @throws ParserException
	 */
	public int parse(String msg, TabState tabstate) throws ParserException{

		//create exp tree
		List<AbstractExpression> exp = this.parser.parse(msg, tabstate);
		
		//prepare to eval exp tree
		int lastEvaluted = -1;
		
		for (AbstractExpression e : exp)
			lastEvaluted = e.evaluate();		//e.evaluate should return the first active turtle result
		return lastEvaluted;
		
	}

}